<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/9
  Time: 10:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>销售机会添加页面</title>
    <%--引入css文件--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
</head>
<body>
<form class="layui-form" >
        <div class="layui-form-item">
            <label class="layui-form-label">客户:</label>
            <div class="layui-input-inline">
                <%--<select name="customer_Id" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="101">客户1</option>
                    <option value="102">客户2</option>
                    <option value="103">客户3</option>
                </select>--%>
                <select name="customer_Id" lay-verify="required">
                    <option value="">请选择</option>
                    <c:forEach items="${sessionScope.customers}" var="customer">
                        <option value="${customer.id}">${customer.name}</option>
                    </c:forEach>
                </select>
            </div>
            <label class="layui-form-label">机会来源:</label>
            <div class="layui-input-inline">
                <select name="source"  lay-verify="required">
                    <option value="">请选择</option>
                    <option value="客户介绍">客户介绍</option>
                    <option value="招标广告">招标广告</option>
                    <option value="广告宣传">广告宣传</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">成功率:</label>
            <div class="layui-input-inline">
                <select name="success"  lay-verify="required">
                    <option value="">请选择</option>
                    <option value="50%"> 50%</option>
                    <option value="60%"> 60%</option>
                    <option value="70%"> 70%</option>
                    <option value="80%"> 80%</option>
                    <option value="90%"> 90%</option>
                </select>
            </div>
            <label class="layui-form-label">客户联系人:</label>
            <div class="layui-input-inline">
                <select name="contact_Id" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="201">联系人1</option>
                    <option value="202">联系人2</option>
                    <option value="203">联系人3</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">机会状态:</label>
            <div class="layui-input-inline">
                <select name="status" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="初期沟通">初期沟通</option>
                    <option value="立项评估">立项评估</option>
                    <option value="解决方案">解决方案</option>
                    <option value="已报价">已报价</option>
                    <option value="商务谈判">商务谈判</option>
                    <option value="合同/订单签订">合同/订单签订</option>
                </select>
            </div>
            <label class="layui-form-label">联系人电话:</label>
            <div class="layui-input-inline">
                <input type="text" name="contact_Phone" lay-verify="number" placeholder="请输入手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">机会概要:</label>
            <div class="layui-input-inline">
                <textarea name="general" placeholder="请输入机会概要的内容，不超过100字" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">机会描述：</label>
            <div class="layui-input-inline">
                <textarea id="description" name="description"></textarea>
            </div>
        </div>
    <input type="hidden" name="creator" value="302">


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

</form>
<%--引入js文件--%>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    //layui引入特定模块,运用模块中方法
    layui.use(['layedit','layer','form',"jquery"],function () {
        var layedit = layui.layedit;//layedit富文本对象
        var layer=layui.layer;//layer弹窗对象
        var form= layui.form;//form表单对象
        var $=layui.$;//jquery对象
        var index =layedit.build('description'); //建立编辑器

        //设置编辑器属性
        layedit.set({
            uploadImage: {//图片上传的接口
                url: '${pageContext.request.contextPath}/sale/uploadImg' //接口url
                ,type: 'post' //默认post
            },
            height:200
        });

        //submit 框监听事件
        form.on("submit(add)",function (data) {
            //将内容同步到textarea
            layedit.sync(index);
            // 获取表单数据项
            console.log( $("form").serialize());
            //异步请求 新增
            $.post("${pageContext.request.contextPath}/sale/add", $("form").serialize(), function (result) {
                if (result.code === 0) {
                    layer.msg("添加成功!");
                    //刷新父窗口的表格 父窗口对象
                    parent.layui.table.reload("test", {
                        page: {
                            curr: 1
                        }
                    });
                    //关闭本窗口
                    //当你在iframe页面关闭自身时
                    var index=parent.layer.getFrameIndex(window.name);//得到当前iframe层索引
                    parent.layer.close(index);//执行关闭
                }
            }, "json");
            return false;
        })

    });
</script>
</body>
</html>
